package com.liss.juc20211122.atomics;

import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;

public class _7LongAdderAPIDemo {
    public static void main(String[] args) {
        LongAdder longAdder = new LongAdder();//只能做加法
        longAdder.increment();
        longAdder.increment();
        longAdder.increment();
        System.out.println(longAdder.longValue());

        LongAccumulator accumulator = new LongAccumulator((x,y)->-x-y,100);
        accumulator.accumulate(1);//1
        accumulator.accumulate(2);//3
        accumulator.accumulate(3);//6

        System.out.println(accumulator.longValue());

    }
}
